#include "defines.hpp"

Cena::Cena(){
  Rotx = 0.0f;
  Roty = 0.0f;
  Rotz = 0.0f;
  camX = 0.0f;
  camY = 0.9f;
  camZ = 0.1f;
  ativo = true;
  n.SetX(0.0f);
  n.SetY(0.2f);
  n.SetZ(-0.8f);
}

Cena::~Cena(){
}

void Cena:: Renderiza(void) {

   glColor3f(1.0f, 0.0f, 0.0f);
   glEnable(GL_DEPTH_TEST);
   glDisable(GL_CULL_FACE);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   gluLookAt(camX,camY,camZ,
             0,0,0,
             0.0f,-1.0f,0.0f);


   glPushMatrix();



   glFrontFace(GL_CCW);
   glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

   n.Desenha(n.getX(), n.getY(), n.getZ());

   glRotatef(Rotx, 1.0f, 0, 0);
   glRotatef(Roty, 0, 1.0f, 0);
   glRotatef(Rotz, 0, 0, 1.0f);

   glPopMatrix();
   glutSwapBuffers();
}

void Cena::Teclas(int key) {


    if(key == GLUT_KEY_F3)
		Rotx-= 5.0f;

	if(key == GLUT_KEY_F4)
		Rotx += 5.0f;

	if(key == GLUT_KEY_F5)
		Roty -= 5.0f;

	if(key == GLUT_KEY_F6)
		Roty += 5.0f;

	if(key == GLUT_KEY_F1){
	    ativo = false;
	    Rotz -= 5.0f;
	}
    if(key == GLUT_KEY_F2)
        Rotz += 5.0f;

    if(key == GLUT_KEY_LEFT)

		n.MoveEsquerda();

	if(key == GLUT_KEY_RIGHT)

		n.MoveDireita();


	if(key > 356.0f) {
	    Rotx = 0.0f;
		Roty = 0.0f;
        Rotz = 0.0f;
	}

	if(key < -1.0f) {
	    Rotx = 355.0f;
		Roty = 355.0f;
		Rotz = 355.0f;	}



	// Refresh the Window
	glutPostRedisplay();
}

void Cena::TeclasComando(unsigned char key){
   if (key == 's'){
     n.Atira();
   }

   if (key == 'g'){
     camX += 0.05f;
   }
   if (key == 'b'){
     camX -= 0.05f;
   }
   if (key == 'h'){
     camY += 0.05f;
   }
   if (key == 'n'){
     camY -= 0.05f;
   }
   if (key == 'j'){
     camZ += 0.05f;
   }
   if (key == 'm'){
     camZ -= 0.05f;
   }
   glutPostRedisplay();
}

void Cena::setAtivo(bool valor){
  ativo = valor;
}

bool Cena::getAtivo(){
  return ativo;
}
